package com.guoning.office_system.service.impl;

import com.guoning.office_system.mapper.RoleMapper;
import com.guoning.office_system.model.Role;
import com.guoning.office_system.model.User;
import com.guoning.office_system.service.RoleService;
import com.guoning.office_system.vo.Criteria;
import com.guoning.office_system.vo.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    RoleMapper roleMapper;

    @Override
    public PageBean<Role> selectRoleByCondition(Criteria criteria, PageBean pageBean) {
        criteria.addExtField("pageIndex", pageBean.getPageIndex() * pageBean.getPageSize());
        criteria.addExtField("pageSize", pageBean.getPageSize());
        List<Role> list = roleMapper.selectRoleByCondition(criteria);
        Long count = roleMapper.selectRoleByConditionCount(criteria);
        pageBean.setTotalCount(count);
        pageBean.setResultList(list);
        return pageBean;
    }

    @Override
    public List<Role> selectByCode(Role role) {
        return roleMapper.selectByCode(role);
    }

    @Override
    public int deleteByIds(List<Role> roles) {
        return roleMapper.deleteByIds(roles);
    }

    @Override
    public int updateEnableByIds(List<Role> roles) {
        return roleMapper.updateEnableByIds(roles);
    }

    @Override
    public int updateDisableByIds(List<Role> roles) {
        return roleMapper.updateDisableByIds(roles);
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return 0;
    }

    @Override
    public int insert(Role record) {
        return 0;
    }

    @Override
    public int insertSelective(Role record) {
        Date now = new Date();
        record.setEnable(0);
        record.setDr(0);
        record.setCreateTime(now);
        record.setTs(now);
        return roleMapper.insertSelective(record);
    }

    @Override
    public Role selectByPrimaryKey(Long id) {
        return null;
    }

    @Override
    public int updateByPrimaryKeySelective(Role record) {
        return roleMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Role record) {
        return 0;
    }
}